use quote::{format_ident, quote};
use proc_macro2::TokenStream as T2;
use syn::Ident;

pub mod gpio;
pub mod gpio_group;
pub mod dma;
pub mod adc;
pub mod dma2;
pub mod uart;

pub enum RccAxB {
    AHB,
    APB1,
    APB2,
}

pub fn rcc_enable(axb: RccAxB, field: &Ident, part: bool) -> T2 {

    let axb_enr = match axb {
        RccAxB::AHB => format_ident!("ahbenr"),
        RccAxB::APB1 => format_ident!("apb1enr"),
        RccAxB::APB2 => format_ident!("apb2enr"),
    };
    let src = quote! {
        use stm32f1::stm32f103::RCC;
        let rcc: RCC = unsafe { ::core::mem::transmute(()) };
        rcc.#axb_enr.modify(|_, w| w.#field().enabled());
    };
    if !part {
        src
    } else {
        quote! {
            {
                #src
            }
        }
    }
}








